package com.farmer.order.feign;

import com.farmer.common.result.Result;
import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * 商品服务Feign客户端
 */
@FeignClient(name = "service-product", fallback = ProductFeignClient.ProductFeignClientFallback.class)
public interface ProductFeignClient {

    /**
     * 获取商品详情
     */
    @GetMapping("/product/{productId}")
    Result<?> getProductById(@PathVariable("productId") Long productId);

    /**
     * 更新商品库存
     */
    @PutMapping("/product/stock/{productId}")
    Result<?> updateStock(@PathVariable("productId") Long productId, @RequestParam("quantity") Integer quantity);

    /**
     * 降级处理
     */
    @Component
    class ProductFeignClientFallback implements ProductFeignClient {

        @Override
        public Result<?> getProductById(Long productId) {
            return Result.error("商品服务暂不可用");
        }

        @Override
        public Result<?> updateStock(Long productId, Integer quantity) {
            return Result.error("商品服务暂不可用，库存更新失败");
        }
    }
} 